from django.db import models


class Car(models.Model):
    """汽车"""
    id = models.AutoField(primary_key=True, verbose_name='编号')
    carno = models.CharField(max_length=15, verbose_name='车牌')
    owner = models.CharField(max_length=20, verbose_name='车主姓名')
    brand = models.CharField(max_length=20, verbose_name='品牌')

    def __str__(self):
        return f'{self.id}: {self.carno}'

    class Meta:
        db_table = 'tb_car'
        verbose_name = '汽车'
        verbose_name_plural = '汽车'


class Record(models.Model):
    """违章记录"""
    id = models.AutoField(primary_key=True, verbose_name='编号')
    car = models.ForeignKey(to=Car, on_delete=models.PROTECT, verbose_name='违章车辆')
    reason = models.CharField(max_length=255, verbose_name='违章原因')
    makedate = models.DateTimeField(verbose_name='违章时间')
    punish = models.CharField(max_length=255, verbose_name='处罚方式')
    dealt = models.BooleanField(default=False, verbose_name='是否受理')

    class Meta:
        db_table = 'tb_record'
        verbose_name = '违章记录'
        verbose_name_plural = '违章记录'
